/*
*************************************************************************************************
*
*	Copyright (C), 2023-2050, ����
*
*	ģ������:   LCD����ģ��
*	�� �� ��:	LCD_HDTR024_240X320_UE.c
* 	��	  ��:	����
* 	��	  ��:	1.0
* 	˵	  ��:	����LCD_HDTR024_240X320_UE����������IC��ʼ�������ļ���
*				�ߴ�:	2.4��
*				�ֱ���:	240X320
*				����IC:	GC9307
*				ICͨѶ:	8λ16λ8080�ӿ�
*
*	�޸ļ�¼:	
*	   �汾��	����			����            ˵��
*      V1.0		2022-02-19   	����    		��ʼ�汾
*
*
**************************************************************************************************
*/
#include "LCD_HDTR024_240X320_TS.h"

#if(LCD_PANEL_TYPE == LCD_HDTR024_240X320_TS)

/*
***************************************
*	��  �ܣ�LCD��Ļ����
***************************************
*/
LcdTiming_T g_lcdTiming = {
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	
	0,
	0,
	0,
	0,
	0
};
#define HORIZONTAL_SCREEN	0
#define FRAME_RATE			60
LcdInfo_T	g_lcdInfo = {
#if	HORIZONTAL_SCREEN
	.pixelWidth		= 320,
	.pixelHeight	= 240,
#else
	.pixelWidth		= 240,
	.pixelHeight	= 320,
#endif	
	.wRamCmd		= 0X2C,
	.setXCmd		= 0X2A,
	.setYCmd		= 0X2B, 
	.colorFormat	= LCD_COLOR_FORMAT_RGB565,	
	.interType		= LCD_DRIVE_I8080,
#if	HORIZONTAL_SCREEN
#if (FRAME_RATE == 60)
	.frameRate		= 60,
	.clockDiv		= 4352
#else
	.frameRate		= 60,
	.clockDiv		= 8743
#endif
#else
#if (FRAME_RATE == 60)
	.frameRate		= 60,
	.clockDiv		= 3292
#else
	.frameRate		= 30,
	.clockDiv		= 6584
#endif
#endif

};

#define WriteComm 			Lcd_WReg
#define WriteData 			Lcd_WData

void Lcd_Drive_Init(void)	
{
	WriteComm(0x11);
	HAL_Delay(120); //Delay 120ms
	//--------------------------------ST7789S Frame rate setting----------------------------------//
	WriteComm(0xb2);
	WriteData(0x0c);
	WriteData(0x0c);
	WriteData(0x00);
	WriteData(0x33);
	WriteData(0x33);

	WriteComm(0xb7);
	WriteData(0x35);   //VGH=13V, VGL=-10.4V
	//---------------------------------ST7789S Power setting--------------------------------------//
	WriteComm(0xbb);
	WriteData(0x22); 	   //28

	WriteComm(0xc0);
	WriteData(0x2c);

	WriteComm(0xc2);
	WriteData(0x01);

	WriteComm(0xc3);
	WriteData(0x20);		 //μ÷é??3   0b

	WriteComm(0xc4);
	WriteData(0x20);

	WriteComm(0xc6);
	WriteData(0x0f);


	WriteComm(0xd0);
	WriteData(0xa4);
	WriteData(0xa1);

	WriteComm(0x3A);
	WriteData(0x05);
	
	WriteComm(0x35);
	WriteData(0x00);

	//--------------------------------ST7789S gamma setting---------------------------------------//
	WriteComm(0xe0);
	WriteData(0xd0);
	WriteData(0x03);
	WriteData(0x08);
	WriteData(0x0b);
	WriteData(0x0f);
	WriteData(0x2c);
	WriteData(0x41);
	WriteData(0x54);
	WriteData(0x4e);
	WriteData(0x07);
	WriteData(0x0e);
	WriteData(0x0c);
	WriteData(0x1e);
	WriteData(0x23);

	WriteComm(0xe1);
	WriteData(0xd0);
	WriteData(0x03);
	WriteData(0x09);
	WriteData(0x0b);
	WriteData(0x0d);
	WriteData(0x19);
	WriteData(0x3c);
	WriteData(0x54);
	WriteData(0x4f);
	WriteData(0x0e);
	WriteData(0x1d);
	WriteData(0x1c);
	WriteData(0x20);
	WriteData(0x22);


	WriteComm(0x29);

}

#endif

